from flask import Flask

from apps.article.views import article_bp
from apps.user.views import user_bp
from exts import db, bootstrap, cache
from settings import ProductionConfig

config = {
    'CACHE_TYPE': 'redis',
    'CACHE_REDIS_HOST': '121.40.254.79',
    'CACHE_REDIS_port': 6379
}


def create_app():
    app = Flask(__name__, template_folder='../templates', static_folder='../static')
    app.config.from_object(ProductionConfig)

    db.init_app(app=app)

    bootstrap.init_app(app=app)
    cache.init_app(app=app, config=config)
    app.register_blueprint(user_bp)
    app.register_blueprint(article_bp)

    return app
